package com.myproject.filmrecommendationsys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.myproject.filmrecommendationsys.domain.User;
import com.myproject.filmrecommendationsys.service.IUserService;
import com.myproject.filmrecommendationsys.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 用户Controller
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户管理")
public class UserController
{
    @Autowired
    private IUserService userService;

    /**
     * 查询用户列表
     */

    @GetMapping("/list")
    @ApiOperation(value = "用户列表")
    public AjaxResult list(User user)
    {
        List<User> list = userService.selectUserList(user);
        return AjaxResult.success(list);
    }

    /**
     * 获取用户详细信息
     */

    @GetMapping(value = "/{id}")
    @ApiOperation(value = "用户详情")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(userService.selectUserById(id));
    }

    /**
     * 新增用户
     */

    @PostMapping("/add")
    @ApiOperation(value = "用户新增")
    public AjaxResult add(@Valid @RequestBody User user)
    {
        return AjaxResult.success(userService.insertUser(user));
    }

    /**
     * 修改用户
     */
    @PutMapping("/update")
    @ApiOperation(value = "用户修改")
    public AjaxResult edit(@RequestBody User user)
    {
        return AjaxResult.success(userService.updateUser(user));
    }

    /**
     * 删除用户
     */
	@DeleteMapping("/{ids}")
    @ApiOperation(value = "用户删除")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return AjaxResult.success(userService.deleteUserByIds(ids));
    }
}
